import {useState} from 'react';
import {View, Text, Button, Alert} from 'react-native';

export default function App() {
  const [num, setNum] = useState(100);

  // 父组件接收数据
  const bbb = (i: number) => {
    // Alert.alert('父组件接收到了' + i.toString());
    setNum(num + i);
  };

  return (
    <View>
      <Text>========</Text>
      <Text>父组件的数字{num}</Text>
      <Child num={num} aaa={bbb} />
      <Text>--------</Text>
    </View>
  );
}

// 自组件
function Child({num, aaa}: {num: number; aaa: (i: number) => void}) {
  return (
    <View>
      <Text>Child</Text>
      <Text>子组件的数字{num}</Text>
      <Button title="增加计数1" onPress={() => aaa(1)} />
      <Button title="增加计数2" onPress={() => aaa(2)} />
    </View>
  );
}
